import * as Cesium from 'cesium'
import { DiffusionEllipse } from './RegisterDiffusionEllipse'

// entity 如果需要自己封装，就不方便了。
// 感觉还不如直接使用 Primitive,可控性也更高。
export function DiffusionEllipseMaterialProperty(options = {}) {
  this._definitionChanged = new Cesium.Event()
  this._color = undefined
  this._speed = undefined

  this.color = options.color
  this.speed = options.speed
  this.defaultSpeed = 1
}

Object.defineProperties(DiffusionEllipseMaterialProperty.prototype, {
  isConstant: {
    get: function () {
      return Cesium.Property.isConstant(this._color) && Cesium.Property.isConstant(this._speed)
    }
  },

  definitionChanged: {
    get: function () {
      return this._definitionChanged
    }
  },

  color: Cesium.createPropertyDescriptor('color'),
  speed: Cesium.createPropertyDescriptor('speed')
})

DiffusionEllipseMaterialProperty.prototype.getType = function (time) {
  return DiffusionEllipse
}

DiffusionEllipseMaterialProperty.prototype.getValue = function (time, result) {
  if (!Cesium.defined(result)) {
    result = {}
  }
  result.color = Cesium.Property.getValueOrClonedDefault(
    this._color,
    time,
    Cesium.Color.WHITE,
    result.color
  )
  result.speed = Cesium.Property.getValueOrDefault(this._speed, time, this.defaultSpeed)
  return result
}

DiffusionEllipseMaterialProperty.prototype.equals = function (other) {
  return (
    this === other || //
    (other instanceof DiffusionEllipseMaterialProperty && //
      Cesium.Property.equals(this._color, other._color) &&
      Cesium.Property.equals(this._speed, other._speed))
  )
}
